#include "BulletHandler.h"

void BulletHandler::addPlayerBullet(int x, int y
        int width, int height,
        std::string textureID, int numFrame, Vector2D heading)
{
    PlayerBullet* pPlayerBullet = new PlayerBullet();
    pPlayerBullet->load(std::unique_ptr<LoaderParams>(
                new LoaderParams(x, y,
                    width, height,
                    textureID, numFrames
                    )
                ),
            heading);
    m_playerBullets.push_back(pPlayerBullet);
}

void BulletHandler::addEnemyBullet(int x, int y
        int width, int height,
        std::string textureID, int numFrame, Vector2D heading)
{
    EnemyBullet* pEnemyBullet = new EnemyBullet();
    pEnemyBullet->load(std::unique_ptr<LoaderParams>(
                new LoaderParams(x, y,
                    width, height,
                    textureID, numFrames
                    )
                ),
            heading);
    m_EnemyBullets.push_back(pEnemyBullet);
}

void BulletHandler::update(){
    for (std::vecotr<PlayerBullet*>::iterator p_it =
            m_playerBullets.begin();
            p_it != m_playerBullets.end();)
    {
        if((*p_it)->getPosition().getX() < 0
        || (*p_it)->getPosition().getX() > TheGame::Instance()->getGameWidth()
        || (*p_it)->getPosition().getY() < 0
        || (*p_it)->getPosition().getY() > TheGame::Instance()->getGameHeight()
        || (*p_it)->dead()
        ){
            delete * p_it;
            p_it = m_playBullets.earase(p_it);
        }
        else
        {
            (*p_it)->update();
            ++p_it;
        }
    }

}
